﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ProjectTest.Models
{
    public class QLDangKy
    {
        private DBTestDataContext db = new DBTestDataContext();


        //lay toan bo thong itin dang ky
        public IEnumerable<DangKy> GetAll()
        {
            return db.DangKies;
        }
       
        //Create
        public void Create(DangKy dk)
        {
            try
            {
                db.DangKies.InsertOnSubmit(dk);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
        //Edit
        public void Edit(DangKy dkEdited, int mdk)
        {
            DangKy dk = db.DangKies.SingleOrDefault(p => p.MaDK==mdk);
            try
            {
                UpdateInfo(dk, dkEdited);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }

        private void UpdateInfo(DangKy dk, DangKy dkEdited)
        {
            dk.MaSV = dkEdited.MaSV;
            dk.MaHP = dkEdited.MaHP;
            dk.HocKy = dkEdited.HocKy;
            dk.NamHoc = dkEdited.NamHoc;
        }
        //Delete
        public void Delete(int mdk)
        {
            DangKy dk = db.DangKies.SingleOrDefault(p => p.MaDK == mdk);
            try
            {
                db.DangKies.DeleteOnSubmit(dk);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}